import {API} from "@/api/MyAxiosConfig";
import type {
    CampusExperienceInterface,
    EducationalBackgroundInterface,
    InternshipExperienceInterface,
    PassAndInterviewNotificationDTO,
    ProjectExperienceInterface,
    ResumeAndJobInterface,
    ResumeNormalInfoInterface
} from "@/model/type";

/**
 * 获取最新的个人简历基本信息
 * @param tokenStr 用户授权令牌
 * @returns 返回从服务器获取的简历基本信息
 */
export async function getLatestResumeNormalInfoAPI(tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/one",
            method: "GET",
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 更新个人简历基本信息
 * @param resumeNormalInfo 简历基本信息对象
 * @param tokenStr 用户授权令牌
 * @returns 返回从服务器返回的更新结果
 */
export async function updateResumeNormalInfoAPI(resumeNormalInfo: ResumeNormalInfoInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/update",
            method: "POST",
            data: resumeNormalInfo,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 添加教育背景信息
 * @param educationBackground 教育背景对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的添加结果
 */
export async function addEducationBackgroundAPI(educationBackground: EducationalBackgroundInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/educational_background/create",
            method: "POST",
            data: educationBackground,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 获取教育背景信息
 * @param resumeId 简历ID
 * @param tokenStr 用户授权令牌
 * @returns 返回从服务器获取的教育背景信息
 */
export async function getEducationBackgroundAPI(resumeId: string, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/educational_background/all",
            method: "GET",
            params: {
                resumeId: resumeId
            },
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 更新教育背景信息
 * @param educationBackground 教育背景对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的更新结果
 */
export async function updateEducationBackgroundAPI(educationBackground: EducationalBackgroundInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/educational_background/update",
            method: "POST",
            data: educationBackground,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 删除教育背景信息
 * @param ed 教育背景对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的删除结果
 */
export async function deleteEducationBackgroundAPI(ed: EducationalBackgroundInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/educational_background/delete",
            method: "DELETE",
            data: ed,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 添加项目经验信息
 * @param projectExperience 项目经验对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的添加结果
 */
export async function addProjectExperienceAPI(projectExperience: ProjectExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/project_experience/create",
            method: "POST",
            data: projectExperience,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 获取项目经验信息
 * @param resumeId 简历ID
 * @param tokenStr 用户授权令牌
 * @returns 返回从服务器获取的项目经验信息
 */
export async function getProjectExperienceAPI(resumeId: string, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/project_experience/all",
            method: "GET",
            params: {
                resumeId: resumeId
            },
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 删除项目经验信息
 * @param pe 项目经验对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的删除结果
 */
export async function deleteProjectExperienceAPI(pe: ProjectExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/project_experience/delete",
            method: "POST",
            data: pe,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 更新项目经验信息
 * @param projectExperience 项目经验对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的更新结果
 */
export async function updateProjectExperienceAPI(projectExperience: ProjectExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/project_experience/update",
            method: "POST",
            data: projectExperience,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 添加校园经历信息
 * @param campusExperience 校园经历对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的添加结果
 */
export async function addCampusExperienceAPI(campusExperience: CampusExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/campus_experience/create",
            method: "POST",
            data: campusExperience,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 获取校园经历信息
 * @param resumeId 简历ID
 * @param tokenStr 用户授权令牌
 * @returns 返回从服务器获取的校园经历信息
 */
export async function getCampusExperiencesAPI(resumeId: string, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/campus_experience/all",
            method: "GET",
            params: {
                resumeId: resumeId
            },
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 删除校园经历信息
 * @param ce 校园经历对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的删除结果
 */
export async function deleteCampusExperienceAPI(ce: CampusExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/campus_experience/delete",
            method: "DELETE",
            data: ce,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 更新校园经历信息
 * @param campusExperience 校园经历对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的更新结果
 */
export async function updateCampusExperienceAPI(campusExperience: CampusExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/campus_experience/update",
            method: "POST",
            data: campusExperience,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 添加实习经历信息
 * @param internshipExperience 实习经历对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的添加结果
 */
export async function addInternshipExperienceAPI(internshipExperience: InternshipExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/internship_experience/create",
            method: "POST",
            data: internshipExperience,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 获取实习经历信息
 * @param resumeId 简历ID
 * @param tokenStr 用户授权令牌
 * @returns 返回从服务器获取的实习经历信息
 */
export async function getInternshipExperiencesAPI(resumeId: string, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/internship_experience/all",
            method: "GET",
            params: {
                resumeId: resumeId
            },
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 删除实习经历信息
 * @param ie 实习经历对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的删除结果
 */
export async function deleteInternshipExperienceAPI(ie: InternshipExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/internship_experience/delete",
            method: "DELETE",
            data: ie,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 更新实习经历信息
 * @param internshipExperience 实习经历对象
 * @param tokenStr 用户授权令牌
 * @returns 返回服务器返回的更新结果
 */
export async function updateInternshipExperienceAPI(internshipExperience: InternshipExperienceInterface, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/internship_experience/update",
            method: "POST",
            data: internshipExperience,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 获取简历和职位信息
 * @param resumeId 简历ID
 * @param tokenStr 用户授权令牌
 * @returns 返回从服务器获取的简历和职位信息
 */
export async function getResumeVO(resumeId: string, tokenStr: string) {
    try {
        const response = await API({
            url: "/resume/resume_and_models",
            method: "GET",
            params: {
                resumeId: resumeId
            },
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 获取检查简历的API接口
 * @param tokenStr 用于认证的token字符串
 * @returns 返回检查简历后的响应数据
 */
export async function getCheckResumeVOAPI(tokenStr: string) {
    try {
        // 使用提供的token进行认证，请求检查简历的API
        const response = await API({
            url: "/resume_and_job/list/check_resume",
            method: "GET",
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 标记简历未通过的API接口
 * @param resumeAndJob 包含简历和工作信息的对象
 * @param tokenStr 用于认证的token字符串
 * @returns 返回未通过操作后的响应数据
 */
export async function noPassResumeAPI(resumeAndJob: ResumeAndJobInterface, tokenStr: string) {
    try {
        // 使用提供的token进行认证，提交简历未通过的API请求
        const response = await API({
            url: "/resume_and_job/no_pass",
            method: "POST",
            data: resumeAndJob,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}

/**
 * 标记简历通过的API接口
 * @param dto 包含通过和面试通知信息的数据传输对象
 * @param tokenStr 用于认证的token字符串
 * @returns 返回简历通过操作后的响应数据
 */
export async function passResumeAPI(dto: PassAndInterviewNotificationDTO, tokenStr: string) {
    try {
        // 使用提供的token进行认证，提交简历通过和面试通知的API请求
        const response = await API({
            url: "/resume_and_job/pass",
            method: "POST",
            data: dto,
            headers: {
                Authorization: tokenStr
            }
        })
        return response.data;
    } catch (error) {
        console.error('axios error:', error.message);
    }
}